import mongoose from 'mongoose';
import Kutils from '../modules/Kutils';

const kutil = new Kutils();
const TABLE_NAME = 'client_msg';

function createdTime() {
    return +new Date();
}

function createdDate() {
    return new Date();
}

function formatDate() {
    return kutil.dateFormat(new Date());
}

const schema = new mongoose.Schema({
    createdDate: { type: Date, default: createdDate },
    createdTime: { type: Number, default: createdTime },
    updatedTime: { type: Number, default: createdTime },
    formatDate: { type: String, default: formatDate },
    serialId: { type: String },
    isUsed: { type: Boolean, default: false },
    param: {
        sys: { type: String },
        wid: { type: Number },
        tableId: { type: Number },
        tableNo: { type: String },
        openId: { type: String },
    },
    data: {
        cmd: { type: String },
        tableNo: { type: String },
    },
}, { versionKey: false });

export const model = mongoose.model(TABLE_NAME, schema);
